import java.awt.Color;

import uchicago.src.sim.gui.Drawable;
import uchicago.src.sim.gui.SimGraphics;
import uchicago.src.sim.space.Multi2DGrid;
import uchicago.src.sim.space.Multi2DHexagonalGrid;
import uchicago.src.sim.space.Object2DTorus;
import uchicago.src.sim.util.Random;


public class Cell implements Drawable{
	private int x, y;
	boolean arder;
	boolean ardeuTotal;
	float densidade;
	float percArder;
	float prob;
	private int focoIncendio;
	Color color;
	private Multi2DGrid space;
	
	boolean extinct;
	boolean drowning;
	
	public Cell(int x, int y, Multi2DGrid space){
		this.x = x;
		this.y = y;
		this.space = space;
		this.arder = false;
		this.percArder = 0;
		this.densidade = Random.uniform.nextIntFromTo(0, 100);
		if(this.densidade < 25){
			color = new Color(0,238,0);
		}
		else if(this.densidade < 50){
			color = new Color(0,205,0);
		}
		else if(this.densidade < 75){
			color = new Color(0,139,0);
		}
		else{
			color = new Color(0,100,0);
		}
		
		this.drowning = false;
		this.extinct = false;
	}
	
	@Override
	public void draw(SimGraphics g) {
		// TODO Auto-generated method stub
		g.drawFastCircle(color);
	}
	@Override
	public int getX() {
		// TODO Auto-generated method stub
		return x;
	}
	@Override
	public int getY() {
		// TODO Auto-generated method stub
		return y;
	}
	public boolean arder() {
		// TODO Auto-generated method stub
		return arder;
	}
	
	public void setFoco(int foco){
		this.focoIncendio = foco;
	}
	
	public int getFoco(){
		return focoIncendio;
	}
	
	public boolean getDrowning(){
		return drowning;
	}
	
	public void burn() {
		 arder = true;
		 percArder = 1;
		 color = new Color(255,255,0);
	}
	
	public boolean apagaFogo(){
		System.out.println("Estou a apagar");
		
		drowning=true;
		
		
		percArder-=5;
		if(percArder < 0){ 
			arder = false; 
			ardeuTotal = true;
			color = color.black;
			extinct = true;
			return false;
		}
		else color = color.CYAN;
		return true;
	}
	
	public boolean fireboost(){
		if(percArder < 100 && !ardeuTotal) percArder+=2;
		else if(percArder >= 100){ ardeuTotal = true; percArder-=1/densidade;}
		else if(percArder > 0 && ardeuTotal) percArder-=1/densidade;
		
		if(percArder <= 0 && ardeuTotal){
			arder = false; color = color.black;
			extinct = true;
			return false;
		}
		else{
			if(this.percArder < 25){
				color = new Color(255,255,0);
			}
			else if(this.percArder < 50){
				color = new Color(255,165,0);
			}
			else if(this.percArder < 75){
				color = new Color(255,69,0);
			}
			else{
				color = new Color(255,0,0);
			}
		}
		return true;
		
	}
	
	
}
